

function validateFirst(cat) {
    
    var isValid = true;
    //RadioButton Type
    if (valButton($("input[name=catId]")) == null) {
        $("#TypeVal").attr('class',"field-validation-error");
        $("#catControl").addClass("error");
        isValid = false;
    }
    else {
        $("#TypeVal").attr('class',"field-validation-valid");
        $("#catControl").removeClass("error");
    }      
    //second fase
    if (isValid) { 
        
        //if($('#plugin-hook').html() == '') { LoadAttributes(); }        
        //var cat = $("input[name='catId']:checked").val();   
        //alert(cat);
        var type_id = VeicleTypeWrapper(cat);          
        fillVeicleModel(type_id);
        //if($('#make').val() == '' || $('#make').val() == 'undefined') { fillVeicleModel(type_id); }
        
        preloadAttr(type_id);
        
        showPanel("addTruckSecond", "addTruckFirst");
        $("#progressBar").css("width","33%");
        $("#step").html("2");        
        $("#summaryStr").html(PostItemCategoryStr());
    }
    return isValid;
}
function backFirst() {   
    showPanel("addTruckFirst", "addTruckSecond");
    $("#progressBar").css("width","0%");
    $("#step").html("1");
    $("#summaryStr").html(PostItemCategoryStr());
}
function validateSecond() {
   
    var isValid = validateItemAttr();
    if (isValid) {
        showPanel("addTruckThird", "addTruckSecond"); 
        $("#progressBar").css("width","66%");
        $("#step").html("3");
        
        $("#summaryStr").html(PostItemTitleStr());
    }        
}
function backSecond() {
    showPanel("addTruckSecond", "addTruckThird");
    $("#progressBar").css("width","33%");
    $("#step").html("2");
    $("#summaryStr").html(PostItemTitleStr());
}
function validateThird() {
    var isValid = true;
    if (isValid) {	
        //Set title value
        var titleStr = ItemTitle();
        var brandStr = ItemBrand();
        //var titleStr = $('#make option:selected').text() + ' - ' + $('#model option:selected').text();
        
        $('#titleId').val(titleStr);	
        $('#meta_item_brand').val(brandStr);	
        if($('#descId').val() == '') $('#descId').val(' ');

        showPanel("addTruckFourth", "addTruckThird");  
        $("#progressBar").css("width","100%");	
        $("#step").html("4");
        
        if($("#price").val() != '') {           
            $("#summaryStr").html(PostItemAll());
        }
    }        
}
function backThird() {	
    if($('#descId').val() == ' ') $('#descId').val('');
    showPanel("addTruckThird", "addTruckFourth");
    $("#progressBar").css("width","66%");
    $("#step").html("3");
}


 function preloadAttr(idVehicleType) {
     
     /*$("#seatsPnl").css("display", "inline");
     $("#fuelPnl").css("display", "inline");
     $("#powerPnl").css("display", "inline");
     $("#cabPnl").css("display", "inline");
     $("#mileagePnl").css("display", "inline");
     $("#payloadPnl").css("display", "inline");
     $("#suspensionPnl").css("display", "inline");
     $("#axisPnl").css("display", "inline");
     $("#makePnl").css("display","inline");
     //$("#titleAuxPnl").css("display","none");*/
     $("#seatsPnl").show();
     $("#fuelPnl").show();
     $("#powerPnl").show();
     $("#cabPnl").show();
     $("#mileagePnl").show();
     $("#payloadPnl").show();
     $("#suspensionPnl").show();
     $("#axisPnl").show();
     $("#makePnl").show();
     if($("#descaux").val() == "")
        $("#titleAuxPnl").hide();
     
     
 switch(idVehicleType) {
     case 1: 
     case 3:
     case 4:
     case 6:
         /*$("#seatsPnl").css("display", "none");
         $("#fuelPnl").css("display", "none");*/
         $("#seatsPnl").hide();
         $("#fuelPnl").hide();
         break;
     case 2: 
     case 5:
         /*$("#seatsPnl").css("display", "none");
         $("#fuelPnl").css("display", "none");
         $("#powerPnl").css("display", "none");
         $("#cabPnl").css("display", "none");
         $("#mileagePnl").css("display", "none");*/
         $("#seatsPnl").hide();
         $("#fuelPnl").hide();
         $("#powerPnl").hide();
         $("#cabPnl").hide();
         $("#mileagePnl").hide();
         break;
     case 7: //maquinaria        
          /*$("#makePnl").css("display","none");
         $("#titleAuxPnl").css("display","inline");
         
        $("#seatsPnl").css("display", "none");
         $("#fuelPnl").css("display", "none");
         $("#payloadPnl").css("display", "none");
         $("#suspensionPnl").css("display", "none");
         $("#axisPnl").css("display", "none");
         $("#cabPnl").css("display", "none");*/
         $("#makePnl").hide();
         $("#titleAuxPnl").show()
                     
         $("#seatsPnl").hide();
         $("#fuelPnl").hide();
         $("#payloadPnl").hide();
         $("#suspensionPnl").hide();
         $("#axisPnl").hide();
         $("#cabPnl").hide();
         break;
     case 8://Autobus
        /* $("#makePnl").css("display","none");
         $("#titleAuxPnl").css("display","inline");
         
         $("#fuelPnl").css("display", "none");
         $("#payloadPnl").css("display", "none");
         $("#suspensionPnl").css("display", "none");
         $("#axisPnl").css("display", "none");
         $("#cabPnl").css("display", "none");*/
         $("#makePnl").hide();
         $("#titleAuxPnl").show();         
         $("#fuelPnl").hide();
         $("#payloadPnl").hide();
         $("#suspensionPnl").hide();
         $("#axisPnl").hide();
         $("#cabPnl").hide();
         break;
     case 9://Furgoneta
         /*$("#suspensionPnl").css("display", "none");
         $("#axisPnl").css("display", "none");
         $("#cabPnl").css("display", "none");*/
         $("#suspensionPnl").hide();
         $("#axisPnl").hide();
         $("#cabPnl").hide();
         break;
     
    }
 
 }   

 
 function PostItemCategoryStr() {
     return $("input[name='catId']:checked").attr('id').replace('id_', '');
 }
 
 function PostItemTitleStr() {
     return PostItemCategoryStr() + " " + "<i class=\"icon-chevron-right\"></i> " + ItemTitle();
 }
 
 function PostItemAll() {
      return PostItemTitleStr() + " " + "<i class=\"icon-chevron-right\"></i> " + 
            $("#price").val() + " " + $("#currencySymbol").text();
 }
 
 function ItemTitle() {
     
     var titleStr = "";
        if($('#make option:selected').val() != -1 && $('#make option:selected').val() != "")
            titleStr += $('#make option:selected').text() + " - ";
        if ($('#model option:selected').val() != -1 && $('#model option:selected').val() != "")
            titleStr += $('#model option:selected').text();
        if ($('#descaux').val() != "")
            titleStr += $('#descaux').val();
        
     return titleStr;
 }
 
  function ItemBrand() {
     
     var titleStr = "";      
      if($('#make option:selected').val() != -1 && $('#make option:selected').val() != "")
            titleStr += $('#make option:selected').text();     
     return titleStr;
 }
 
 function LoadAttrItemEdit()
 {
     if ($('#make option:selected').val() == -1 || $('#model option:selected').val() == -1)
     {
        if( $('#make option:selected').val() == -1)
        {
            $("#modelPnl").css("display","none");
        }
        $("#titleAuxPnl").css("display","");
        if($("#descaux").val() == "")  $("#descaux").val($('#titleId').val());
    }
 }
 
 function validateItemAttr() {
   
    var isValid = true;
    
    if($("#makePnl").css("display") != "none")
    {
        var makeIsValid = text_validation($("#make"));
        if(!makeIsValid) { isValid = false; $("#make").focus(); }
        else removeError($("#make"));
    }
    
    var regIsValid = text_validation($("#registration"));
    if(!regIsValid) { isValid = false; $("#registration").focus(); }
    else removeError($("#registration"));
    
    if($("#modelPnl").css("display") != "none")
    {
        var modelIsValid = text_validation($("#model"));
        if(!modelIsValid) { isValid = false; $("#model").focus(); }
        else removeError($("#model"));
    }
    if($("#titleAuxPnl").css("display") != "none")
    {
       var titleAuxIsValid = text_validation($("#descaux"));
        if(!titleAuxIsValid) { isValid = false; $("#descaux").focus(); }
        else removeError($("#descaux"));     
    }
    return isValid;
 }